package boundarys;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;

import ccrm.BoundryControl;
import controllers.UserController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

import entitys.Session;

import java.awt.Font;
import java.awt.Color;
import java.io.IOException;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class RGUI extends AbstractGUI{

	private JFrame frmCcrmR;
	private String userid;
	private String userpw;
	

	/**
	 * Create the application.
	 */
	public RGUI(String userid, String userpw) {
		this.userid = userid;
		this.userpw = userpw;
		initialize();
		initGUI(frmCcrmR);
		frmCcrmR.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{228, 201, 222, 242, 170, 0};
		gridBagLayout.rowHeights = new int[]{77, 36, 65, 38, 17, 50, 44, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmCcrmR.getContentPane().setLayout(gridBagLayout);
		
		JLabel lblResellerPanel = new JLabel("Reseller Panel");
		lblResellerPanel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		GridBagConstraints gbc_lblResellerPanel = new GridBagConstraints();
		gbc_lblResellerPanel.fill = GridBagConstraints.BOTH;
		gbc_lblResellerPanel.insets = new Insets(0, 0, 5, 5);
		gbc_lblResellerPanel.gridx = 2;
		gbc_lblResellerPanel.gridy = 0;
		frmCcrmR.getContentPane().add(lblResellerPanel, gbc_lblResellerPanel);
		
		JButton RTMOBtn = new JButton("Refer To Marketing Offers");
		RTMOBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new ReferMarketingOffersGUI();
				}
			}
		});
		GridBagConstraints gbc_RTMOBtn = new GridBagConstraints();
		gbc_RTMOBtn.fill = GridBagConstraints.BOTH;
		gbc_RTMOBtn.insets = new Insets(0, 0, 5, 5);
		gbc_RTMOBtn.gridx = 2;
		gbc_RTMOBtn.gridy = 2;
		frmCcrmR.getContentPane().add(RTMOBtn, gbc_RTMOBtn);
		
		JButton logOut = new JButton("Log Out");
		logOut.setForeground(Color.RED);
		logOut.setFont(new Font("Tahoma", Font.BOLD, 11));
		logOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					goBack();
					UserController.LogoutUser(getUserid(), getUserpw());
				}
			}
		});
		GridBagConstraints gbc_logOut = new GridBagConstraints();
		gbc_logOut.fill = GridBagConstraints.BOTH;
		gbc_logOut.insets = new Insets(0, 0, 5, 5);
		gbc_logOut.gridx = 1;
		gbc_logOut.gridy = 5;
		frmCcrmR.getContentPane().add(logOut, gbc_logOut);
		frmCcrmR.setVisible(true);
	}

	public String getUserpw() {
		return userpw;
	}

	public void setUserpw(String userpw) {
		this.userpw = userpw;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCcrmR = new JFrame();
		frmCcrmR.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				UserController.LogoutUser(getUserid(), getUserpw());
			}
		});
		frmCcrmR.setResizable(false);
		frmCcrmR.setTitle("CCRM>Reseller Management");
		frmCcrmR.setBounds(100, 100, 417, 272);
		frmCcrmR.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void getReply(Object r) {
		// TODO Auto-generated method stub

		
	}
}
